#pragma once
#include <string>
#include "MemoryOperator.h"

#define S_OPEN_NONE 0
#define S_OPEN_FILE 1
#define S_OPEN_TEXT 2
#define S_OPEN_BINARY 3
#define S_OPEN_HTML 4
#define S_OPEN_DIR 5

class HTTPContent
{
public:
	HTTPContent();
	virtual ~HTTPContent();

	// 关闭
	void close();

	/*
	 打开内容
	 NO.1 缓冲区
	 NO.2 缓冲区长度
	 NO.3 打开文件类型
	*/
	bool open(const char * buffer, unsigned int length, unsigned int type);

	// 读入内容
	unsigned int write(const char * buffer, unsigned int length);

	// s是否可以打开
	inline bool isOpen() { return this->openType != S_OPEN_NONE; }

	const std::string lastModifield();

	/*https://baike.baidu.com/item/ETag/4419019?fr=aladdin*/
	std::string getETag();

	std::string getContentType();

	// 获取内容长度
	size_t getContentLength();

	std::string HTTPContent::getContentRange();

	// 读取内容
	size_t read( char * buffer, size_t length);

protected:

	// 打开类型
	unsigned int openType;

	// 内容类型
	std::string contentType;

	// 文件名
	std::string fileName;

	// 文件信息结构体
	struct _stat32i64 fileInfo;

	// 缓冲区
	MemoryOperator<char> memOperator;

	// 根据文件类型获取 Content-Type
	static std::string getContentTypeByFileName();

	// getContentType 附属方法
	static std::string * contentTypeComponent();

private:

	HTTPContent(HTTPContent &);

	HTTPContent & operator = (HTTPContent &);
};

